﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ShareMarking.Service;
using ShareMarking.Entity;

namespace ShareMarking.Api
{
    public partial class Test : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!Page.IsPostBack)
            {

            }
        }

        protected void Button1_Click(object sender, EventArgs e)
        {
            #region 组装返回
            var ds = qr_QrCodeRelateService.Instance.db.From<qr_QrCodeRelate>()
                .InnerJoin<qr_QrCode>(qr_QrCodeRelate._.qr_Scene_ID == qr_QrCode._.scene_id)
                .Where(qr_QrCodeRelate._.qr_Type == 2).ToDataSet();

            results results = new Api.results();
            results.subcode = "00";
            results.msg = "成功";

            List<hosp> alist = new List<hosp>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                hosp hosp = new hosp()
                {
                    hospid = ds.Tables[0].Rows[i]["rel_Code"].ToString(),
                    hospname = ds.Tables[0].Rows[i]["title"].ToString(),
                    code_url = ds.Tables[0].Rows[i]["code_url"].ToString(),
                    qrcode_url = ds.Tables[0].Rows[i]["qrcode_url"].ToString(),
                };
                alist.Add(hosp);
            }
            result result = new Api.result()
            {
                countNum = ds.Tables[0].Rows.Count.ToString(),
                alist = alist
            };
            results.result = result;
            #endregion

            string re = ComLib.JsonHelper.JsonSerializer<results>(results);
            Response.Write(re);
            ComLib.LogLib.Log4NetBase.Log("1、返回医院二维码数据:条数:" + alist.Count);
        }
    }

    public class results
    {
        public string subcode;
        public string msg;
        public result result;
    }
    public class result
    {
        public string countNum;
        public List<hosp> alist;
    }

    public class hosp
    {
        public string hospid;
        public string hospname;
        public string code_url;
        public string qrcode_url;
    }
}